<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <style type="text/css">
        body, html {
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }

        #l-map {
            height: 300px;
            width: 100%;
        }

        #r-result, #r-result table {
            width: 100%;
        }
    </style>
    <script src="http://api.map.baidu.com/api?v=2.0&ak=9ABKWGfMocRTDIOoNVW9ztZjfbLvgNuK"
            type="text/javascript"></script>
    <title>导航</title>
</head>
<body>
<!--<div style="height: 24px;width: 100%;"-->
     <!--onclick="javascript:window.history.back();">-->
    <!--<img height="32px" width="32px" src="/img/wx/ic_back.png">-->
<!--</div>-->
<div id="l-map"></div>
<div id="r-result"></div>

</body>
</html>
<script type="text/javascript">

    // 百度地图API功能
    var map = new BMap.Map("l-map");
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
    /*30.7047596781,104.0293411003*/
    /*中国四川省成都市金牛区茶店子横街6号*/
    var lng, lat;
    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function (r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
            var mk = new BMap.Marker(r.point);
            map.addOverlay(mk);
            map.panTo(r.point);
            // alert('您的位置：' + r.point.lng + ',' + r.point.lat);
            lng = r.point.lng
            lat = r.point.lat

            var p1 = new BMap.Point(lng, lat);//起点
            var p2 = new BMap.Point(104.0293411003, 30.7047596781);//终点

            var myIcon = new BMap.Icon("img_target.png", new BMap.Size(180, 140));
            var marker2 = new BMap.Marker(p2, {icon: myIcon});  // 创建标注
            map.addOverlay(marker2);

            var driving = new BMap.DrivingRoute(map, {
                renderOptions: {
                    map: map,
                    panel: "r-result",
                    autoViewport: true
                }
            });
            driving.search(p1, p2);
        }
        else {
            alert('failed' + this.getStatus());
        }
    }, {enableHighAccuracy: true})


</script>
